//
//  SPHomeCollectionViewCell.swift
//  Swift-demo
//
//  Created by zcp on 2021/9/29.
//

import UIKit

class SPHomeCollectionViewCell: SPBaseCollectionViewCell {
    
    private lazy var imgV: UIImageView = {
        let imgV = UIImageView()
        imgV.clipsToBounds = true
        imgV.contentMode = .scaleAspectFill
        imgV.layer.cornerRadius = 5
        return imgV
    }()
    
    private lazy var titleL: UILabel = {
        let label = UILabel()
        label.font = UIFont.systemFont(ofSize: 14)
        label.textColor = UIColor.black
        return label
    }()
    
    private lazy var desL: UILabel = {
        let label = UILabel()
        label.font = UIFont.systemFont(ofSize: 12)
        label.textColor = UIColor.gray
        return label
    }()
    
    override func initUI() {
        contentView.addSubview(desL)
        desL.snp.makeConstraints { make in
            make.bottom.equalToSuperview()
            make.left.right.equalToSuperview()
        }
        
        contentView.addSubview(titleL)
        titleL.snp.makeConstraints { make in
            make.bottom.equalTo(desL.snp_top).offset(-10)
            make.left.right.equalTo(desL)
        }
        
        contentView.addSubview(imgV)
        imgV.snp.makeConstraints { make in
            make.top.left.right.equalToSuperview()
            make.bottom.equalTo(titleL.snp_top).offset(-10)
        }
    }
    
    override func setData(dict: [String : Any], indexPath: NSIndexPath?) {
        imgV.image = UIImage(named: dict["icon"] as! String)
        titleL.text = dict["title"] as? String
        desL.text = dict["title"] as? String
    }
    
    var model: ItemModel? {
        didSet {
            guard let model = model else { return }
            imgV.kf.setImage(with: URL(string: model.cover ?? ""), placeholder: (bounds.width > bounds.height) ? UIImage(named: "normal_placeholder_h") : UIImage(named: "normal_placeholder_v"))
            titleL.text = model.title
            desL.text = model.subTitle
        }
    }
    
}
